//
//  BottomSinglePixelLineView.m
//  OntheRoadV4
//
//  Created by hz on 11/8/13.
//  Copyright (c) 2013 EricHuang. All rights reserved.
//

#import "BottomSinglePixelLineView.h"
#import "QWKitConfig.h"
#import "CommonCGDrawings.h"

@implementation BottomSinglePixelLineView
{
    CAShapeLayer *_progressLayer;
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        _lineColor = V4_SeparatorLineColor;
        self.backgroundColor = [UIColor clearColor];
        _progressLayer = [CAShapeLayer layer];
        _progressLayer.strokeColor = [UIColor whiteColor].CGColor;
        _progressLayer.fillColor = [UIColor whiteColor].CGColor;
        [self.layer addSublayer:_progressLayer];
    }
    return self;
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    _lineColor = V4_SeparatorLineColor;
    self.backgroundColor = [UIColor clearColor];
}


- (void)setLineColor:(UIColor *)lineColor
{
    _lineColor = lineColor;
    [self setNeedsDisplay];
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    draw1PxHorizontalStroke(context, rect.origin, rect.size.width, _lineColor.CGColor);
}

-(void)setProgress:(CGFloat)progress
{
    _progress = progress;
    UIBezierPath *bPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, -1, CGRectGetWidth(self.frame)*_progress, CGRectGetHeight(self.frame)+1)];
    [_progressLayer setPath:bPath.CGPath];
}

@end
